<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
    <script>
    
    
    function sum(num) {
      var sum1=0
      for(var i=num;i>=0;i--){
          sum1+=i
      }
      return sum1
    }
    console.log(sum(100))//5050
    console.log(sum(10))
    console.log(sum(5))


    console.log("==========================")

      function sumN(n){
    if(n<=0){
    console.log("你传入的数据有误")
    return
        }//加上对n的判断
    var sum=0
    for(var i=1;i<=n;i++){
      sum+=i
    }
    return sum
     }
     var sum=sumN(100)
     var result=sumN(5)
    console.log(sum)
    console.log(`1~5的和是${result}`)
    </script>
</body>
</html>